import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class FloorPanel extends JPanel{
	//	Local variables	
	private JList _notInLineList;
	private JLabel _notInLineLbl;
	private JScrollPane _customerScrollPanel;

	//	Peer objects	
	private StoreLogic _logic;
	private JFrame _parentFrame;

	public FloorPanel(StoreLogic aLogic,JFrame parentFrame)
	{
		super(new BorderLayout());
		_logic = aLogic;
		_notInLineLbl = new JLabel("Customers out in the shop:");
		_notInLineList = new JList(_logic.getNotInLine());
		_notInLineList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		_customerScrollPanel = new JScrollPane(_notInLineList);
		_parentFrame = parentFrame;
		_notInLineList.addMouseListener(new CheckCustuomer());
		this.add(_notInLineLbl,BorderLayout.NORTH);
		this.add(_customerScrollPanel,BorderLayout.CENTER);
	}
	
	private class CheckCustuomer implements MouseListener
	{
		public void mouseClicked(MouseEvent me) 
		{
			if (me.getClickCount() == 2 && _logic.getNotInLine().getSize() != 0) 
			{
				CheckOutFrame _NewCheckOutFrame = new CheckOutFrame(_parentFrame, _logic.getPersonNotLine(_notInLineList.getSelectedIndex()));
			}	
		}
		//	Not used
		@Override
		public void mouseEntered(MouseEvent arg0) {
		}

		@Override
		public void mouseExited(MouseEvent arg0) {
		}

		@Override
		public void mousePressed(MouseEvent arg0) {
		}

		@Override
		public void mouseReleased(MouseEvent arg0) {
		}
	}

	public int getSelectedCustomer()
	{
		return _notInLineList.getSelectedIndex();
	}

}
